import { ClientMsgOff, ClientMsgOn, CreateEventKey, EventCode } from "../events/ClientMsgHandle";
import { Vector3 } from "../math/Vector3";
import { post } from "../utils/Client";
import { Mapper } from "../utils/Map";

/**3d对象 */
class Object3D {
  [key: string]: any;
  guid: string;
  displayname: string;
  @Mapper("position", Vector3)
  position: Vector3;
  @Mapper("rotation", Vector3)
  rotation: Vector3;
  @Mapper("scale", Vector3)
  scale: Vector3;

  constructor() {
    this.guid = "";
    this.displayname = "";
    Object3D.prototype.isObject3D = true;
    const position = new Vector3();
    const rotation = new Vector3();
    const scale = new Vector3(1, 1, 1);
    Object.defineProperties(this, {
      position: {
        configurable: true,
        enumerable: true,
        writable: true,
        value: position,
      },
      rotation: {
        configurable: true,
        enumerable: true,
        writable: true,
        value: rotation,
      },
      scale: {
        configurable: true,
        enumerable: true,
        writable: true,
        value: scale,
      },
    });
  }
  lookAt(x: number | Vector3, y?: number, z?: number) {
    if (x instanceof Vector3) {
    } else {
    }
    if (this.isCamera || this.isLight) {
    } else {
    }
  }
  /**
   * 组件事件
   * @param key "click"|"hover"|"other"事件key
   * @param call 事件回调方法
   */
  on(key:string, call) {
    const eventKey = CreateEventKey(EventCode.NODE_EVENT, this.guid, key);
    ClientMsgOn(eventKey, call);
  }
  /**
   * 销毁事件
   * @param key "click"|"hover"|"other"事件key
   */
  off(key) {
    const eventKey = CreateEventKey(EventCode.NODE_EVENT, this.guid, key);
    ClientMsgOff(eventKey);
  }
  /**
   * 绑定组件事件
   * @param guid guid
   * @param key "click"|"hover"|"other"事件key
   * @param call 事件回调方法
   */
  static bind(guid,key,call){
    const eventKey = CreateEventKey(EventCode.NODE_EVENT, guid, key);
    ClientMsgOn(eventKey, call);
  }
  /**
   * 取消绑定组件事件
   * @param guid guid
   * @param key "click"|"hover"|"other"事件key
   */
  static unbind(guid,key){
    const eventKey = CreateEventKey(EventCode.NODE_EVENT, guid, key);
    ClientMsgOff(eventKey);
  }
}

export { Object3D };
